let path = require('path')
let htmlWEbpackPlugin = require('html-webpack-plugin')
let { CleanWebpackPlugin } = require('clean-webpack-plugin')
let miniCssExtractPlugin = require('mini-css-extract-plugin')
module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'index.[contenthash:8].js',
    path: path.resolve(__dirname, '../dist'),
    assetModuleFilename: 'imgs/[name][ext]'
  },
  plugins: [
    new htmlWEbpackPlugin({
      template: './public/index.html'
    }),
    new CleanWebpackPlugin(),
    new miniCssExtractPlugin({
      filename: 'index.[contenthash:8].css'
    }),
  ],
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [miniCssExtractPlugin.loader, 'css-loader', 'postcss-loader']
      }, {
        test: /\.less$/,
        use: [miniCssExtractPlugin.loader, 'css-loader', 'less-loader', 'postcss-loader']
      },
      {
        test: /\.(jpg|png|webp|gif)$/,
        type: 'asset/resource'
      },
      {
        test: /\.js$/,
        use: ['babel-loader', {
          loader: path.resolve(__dirname, '../myloader.js')
        }],
        exclude: /node_modules/
      }
    ]
  }
}